﻿using Org.BouncyCastle.Crypto.Digests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CallCenter.Common
{
    public static class EncryptHelper
    {
        /// <summary>
        /// Md5加密
        /// </summary>
        /// <param name="plain"></param>
        /// <returns></returns>
        public static string Md5Encrypt(string plain)
        {
            var data = Encoding.UTF8.GetBytes(plain);
            return Md5Encrypt(data);
        }

        public static string Md5Encrypt(byte[] data)
        {
            try
            {
                MD5Digest digest = new MD5Digest();
                digest.BlockUpdate(data, 0, data.Length);
                byte[] md5Buf = new byte[digest.GetDigestSize()];
                digest.DoFinal(md5Buf, 0);
                return BitConverter.ToString(md5Buf).Replace("-", "").ToLower();
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }
    }
}
